package com.itao.spel;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import java.util.Arrays;

/**
 * 数组构造
 * @author sjt
 * @Date 2024/10/9 9:52
 */
public class ArrayConstruction {

    public static void main(String[] args) {
        ExpressionParser parser = new SpelExpressionParser();
        int[] numbers1 = (int[]) parser.parseExpression("new int[4]").getValue();
        System.out.println(Arrays.toString(numbers1)); // [0, 0, 0, 0]
        // Array with initializer
        int[] numbers2 = (int[]) parser.parseExpression("new int[] {1, 2, 3}").getValue();
        System.out.println(Arrays.toString(numbers2)); // [1, 2, 3]
        // Multi dimensional array
        int[][] numbers3 = (int[][]) parser.parseExpression("new int[4][5]").getValue();
        System.out.println(Arrays.toString(numbers3)); // [[I@1134affc, [I@d041cf, [I@129a8472, [I@1b0375b3]
    }
}
